package bRemote
{
	import mx.controls.Alert;
	import mx.rpc.AbstractOperation;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;

	public class BaseRemote
	{
		public function BaseRemote()
		{
		}
		
		// 进一步加工AbstractOperation
		public function machiningAgain(op:AbstractOperation, 
									   result:Function = null, fault:Function = null):void{

			if(fault==null)
			{
				fault=defalutFaultFunc;
			}
			
			if (result != null) {
				op.addEventListener(ResultEvent.RESULT, result);
			}
			if (fault != null) {
				op.addEventListener(FaultEvent.FAULT, fault);
			}
			var f : Function = function() : void {
				op.removeEventListener(ResultEvent.RESULT, f);
				op.removeEventListener(FaultEvent.FAULT, f);
				if (result != null) {
					op.removeEventListener(ResultEvent.RESULT, result);
				}
				if (fault != null) {
					op.removeEventListener(FaultEvent.FAULT, fault);
				}
			}
			op.addEventListener(ResultEvent.RESULT, f);
			op.addEventListener(FaultEvent.FAULT, f);
		}
		
		public function dispose():void
		{
			
		}
		
		
		private function defalutFaultFunc(evt:FaultEvent):void
		{
			Alert.show(evt.fault.message,"查询错误");
		}				
	}
}






